package com.jiazhong.boot.mvc.interceptor.filter;

import jakarta.servlet.FilterChain;
import jakarta.servlet.FilterConfig;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebFilter;
import jakarta.servlet.http.HttpFilter;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Slf4j
@WebFilter("/*")
@Component
public class FirstFilter extends HttpFilter implements Ordered {
    @Override
    public int getOrder() {
        return 97;
    }

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        log.info("This is FirstFilter init!");
    }

    @Override
    protected void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
        log.info("进入了FirstFilter过滤器");
        chain.doFilter(request, response);
        log.info("有经过了FirstFilter过滤器");
    }
}
